
import axios from "axios"

import { useState } from "react"

import { getRouteThunk } from "../../store/userinfo"
import {useDispatch} from "react-redux"
import { useNavigate } from "react-router-dom"


function Login(){

    let dispath = useDispatch()
    let nav = useNavigate()
    let [account,setaccount] = useState(()=>{
        return ""
    })

    let [password,setpassword] = useState(()=>{
        return ""
    })
    const login = ()=>{
        axios.post("http://172.19.200.4:8001/login",{account,password}).then((res)=>{
            let id = res.data.id
            dispath(getRouteThunk(id))
            nav("/page1")
        })
    }
    return <>
        <div>账号:<input type="text" onChange={(e)=>{
            let acc = e.target.value
            setaccount(acc)
        }}></input></div>
        <div>密码:<input type="text" onChange={(e)=>{
            let pass = e.target.value
            setpassword(pass)
        }}></input></div>
        <button onClick={login}>登录</button>
    </>
}



export default Login